<template>
  <div class="bgc">
    <el-form
      :model="loginForm"
      :rules="rules"
      ref="loginForm"
      class="loginContainer"
    >
      <h2 class="logintitle">系统登陆</h2>
      <el-form-item prop="name">
        <el-input
          auto-complete="false"
          v-model="loginForm.name"
          type="text"
          placeholder="请输入用户名"
        ></el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input
          auto-complete="false"
          v-model="loginForm.password"
          type="password"
          placeholder="请输入密码"
        ></el-input>
      </el-form-item>
      <el-form-item prop="code">
        <el-input
          auto-complete="false"
          type="text"
          v-model="loginForm.code"
          placeholder="点击图片更换验证码"
          class="images"
        ></el-input>
      </el-form-item>
      <img :src="captchUrl" alt="" @click="updatacaku" />
      <el-checkbox v-model="loginForm.checked" class="loginremanber"
        >记住我</el-checkbox
      >
      <el-button type="primary" style="width: 100%" @click="logintoken"
        >登陆</el-button
      >
    </el-form>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      captchUrl: "/captcha?time=" + new Date(),
      loginForm: {
        name: "admin",
        password: "123",
        code: "",
        checked: true,
      },
      rules: {
        name: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
          { min: 3, max: 5, message: "长度在 3 到 5 个字符", trigger: "blur" },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
        ],
        code: [
          {
            required: true,
            message: "请输入验证码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    logintoken() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          // alert("submit!");
          this.$message.success("登陆成功");
          this.$router.replace("/home");
        } else {
          // console.log("error submit!!");
          this.$message.error("输入完整信息");
          return false;
        }
      });
    },
    updatacaku() {
      this.captchUrl = "/captcha?time=" + new Date();
    },
  },
};
</script>

<style scoped>
.bgc {
  background: url(../assets/666.jpg) no-repeat;
  background-size: 100%;
  background-position: center center;

  /* background-color: #ccc; */
  height: 100%;
}
.loginContainer {
  border-radius: 15px;
  /* box-sizing: border-box; */
  background-clip: padding-box;
  /* margin: 150px auto; */
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);

  width: 350px;
  padding: 15px 35px 15px 35px;
  background-color: #fff;
  border: 1px solid #eaeaea;
  box-shadow: 0 0 25px #cac6c6;
}
.logintitle {
  text-align: center;
  margin: 0px auto 40px auto;
}
.images {
  width: 250px;
  margin-right: 5px;
}
.loginremanber {
  width: 150px;
  text-align: left;
  margin: 0 0 15px 0;
}
</style>